package com.nutstudio.feitoys.utils;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by admin on 2015/8/10.
 */
    public class PreferenceUtils {

    public static String getPrefString(Context context, String fileName, String key) {

        SharedPreferences sp =  context.getSharedPreferences(fileName, Activity.MODE_PRIVATE);
        return sp.getString(key,"");
    }

    public  static void setPrefString(Context context, String fileName, String key,
                                      String value) {
        SharedPreferences sp =  context.getSharedPreferences(fileName, Activity.MODE_PRIVATE);
        sp.edit().putString(key, value).commit();
    }
    public static boolean getPrefBoolean(Context context, String fileName, String key
                                         ) {
        SharedPreferences sp =  context.getSharedPreferences(fileName, Activity.MODE_PRIVATE);
        return sp.getBoolean(key, Boolean.parseBoolean(""));
    }
    public static void setPrefBoolean(Context context, String fileName, String key,
                                      boolean defaultValue) {
        SharedPreferences sp =  context.getSharedPreferences(fileName, Activity.MODE_PRIVATE);
        sp.edit().putBoolean(key, defaultValue).commit();
    }
    public static int getPrefInt(Context context, String fileName, String key
    ) {
        SharedPreferences sp =  context.getSharedPreferences(fileName, Activity.MODE_PRIVATE);
        return sp.getInt(key,0);
    }
    public static void setPrefInt(Context context, String fileName, String key,
                                  int defaultValue) {
        SharedPreferences sp =  context.getSharedPreferences(fileName, Activity.MODE_PRIVATE);
        sp.edit().putInt(key, defaultValue).commit();
    }
   public  static  void removePreference(Context context, String fileName, String key){
       SharedPreferences sp =  context.getSharedPreferences(fileName, Activity.MODE_PRIVATE);
        sp.edit().remove(key).commit();
   }
    public static void clearPreference(Context context, String fileName){
        SharedPreferences sp =  context.getSharedPreferences(fileName, Activity.MODE_PRIVATE);
            sp.edit().clear().commit();
    }

}

